// pages/password/password.js
function countdown(that) {
  var second = that.data.countdown_time
  if (second == 0) {
    console.log("001");
    // console.log("Time Out...");  
    that.setData({
      // second: "Time Out..."  

      showtime1: true,
      showtime2: false,
      reg_hqyzm: "重新获取",
      countdown_time: 60,
    });
    console.log("002");
    return;
  }
  console.log("003");
  var time = setTimeout(function () {
    that.setData({
      countdown_time: second - 1
    });
    countdown(that);
  }
    , 1000)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showtime1: true,
    showtime2: false,
    reg_hqyzm: "获取验证码",
    countdown_time: 60,
    yzm:''
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  mobileInputEvent: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  reg_yanzhengma_huoqu: function (e) {
    var that=this;
    this.setData({
      showtime1: false,
      showtime2: true,
    });
    var phone = that.data.phone;
    wx.request({
      url: "https://www.135k.com/addons/sd_humans/tp/index.php/register/send",
      data: {
        phone: phone
      },
      method: "post",
      success: function (res) {
        var yzm = res.data;
        that.setData({
          yzm: yzm
        })
      }
    })
    countdown(this);
    // wxTimer.start(this);  
  },
  submit: function (e) {
    var that = this;
    var phone = e.detail.value.phone;
    var code = e.detail.value.code;
    var yzm = that.data.yzm
    if (phone == "" || code == "") {
      wx.showToast({
        title: '不能为空',
        icon: 'none',
        duration: 1500
      })
      return false;
    } else if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))) {
      wx.showToast({
        title: '手机号有误！',
        icon: 'none',
        duration: 1500
      })
      return false;
    }
    else if (yzm==code) {
      setTimeout(function () {				//确认之后跳转的页面
        wx.navigateTo({
          url: '../reset/reset?phone='+phone,
        })
      }, 1500);
    } else {
      wx.showToast({
        title: '验证码错误',
        icon: 'success',
        duration: 1500
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})